package com.foreveross.vo;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.foreveross.common.Constants;

/**
 * HrNewsInfo entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "hr_news_info", catalog = "hrtenement")
public class HrNewsInfo implements java.io.Serializable {

	// Fields

	private String id;
	private SysUser sysUserByCreateId;
	private SysUser sysUserByPublisherId;
	private String createName;
	private String publisherName;
	private String title;
	
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date createTime;
	
	private HrHouses houseId;
	private String image;
	private String imagePath;
	private String content;
	private String contentImgList;
	private String link_url;
	private String publishState;
	private HrCode type;

	private String houseName;

	private String houseid;

	private String typeName;

	private String typeId;
	
	private Integer isAll;
	
	private List<NewsHouse> newsHouses = new ArrayList<NewsHouse>();

	// Constructors

	/** default constructor */
	public HrNewsInfo() {
	}

	/** minimal constructor */
	public HrNewsInfo(String id) {
		this.id = id;
	}

	/** full constructor */
	public HrNewsInfo(String id, SysUser sysUserByCreateId,Integer isAll,
			SysUser sysUserByPublisherId, String title, Date createTime,
			HrHouses houseId, String image, String url, String content,
			String publishState, HrCode type ,String link_url) {
		this.id = id;
		this.sysUserByCreateId = sysUserByCreateId;
		this.sysUserByPublisherId = sysUserByPublisherId;
		this.title = title;
		this.createTime = createTime;
		this.houseId = houseId;
		this.image = image;
		//this.url = url;
		this.content = content;
		this.publishState = publishState;
		this.type = type;
		this.link_url = link_url;
		this.isAll = isAll;
	}

	// Property accessors
	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	@GeneratedValue(generator = "idGenerator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "create_id")
	public SysUser getSysUserByCreateId() {
		return this.sysUserByCreateId;
	}

	public void setSysUserByCreateId(SysUser sysUserByCreateId) {
		this.sysUserByCreateId = sysUserByCreateId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "publisher_id")
	public SysUser getSysUserByPublisherId() {
		return this.sysUserByPublisherId;
	}

	public void setSysUserByPublisherId(SysUser sysUserByPublisherId) {
		this.sysUserByPublisherId = sysUserByPublisherId;
	}

	@Column(name = "title")
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return this.createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "house_id")
	@NotFound(action = NotFoundAction.IGNORE)
	public HrHouses getHouseId() {
		return this.houseId;
	}

	public void setHouseId(HrHouses houseId) {
		this.houseId = houseId;
	}

	@Column(name = "image")
	public String getImage() {
		return this.image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	@Column(name = "content")
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	@Column(name = "content_img_list")
	public String getContentImgList() {
		return contentImgList;
	}

	public void setContentImgList(String contentImgList) {
		this.contentImgList = contentImgList;
	}

	@Column(name = "publish_state")
	public String getPublishState() {
		return this.publishState;
	}

	public void setPublishState(String publishState) {
		this.publishState = publishState;
	}
	
	@Column(name = "link_url")
	public String getLink_url() {
		return link_url;
	}

	public void setLink_url(String link_url) {
		this.link_url = link_url;
	}
	
	@Column(name = "is_all")
	public Integer getIsAll() {
		return isAll;
	}

	public void setIsAll(Integer isAll) {
		this.isAll = isAll;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "type")
	@NotFound(action = NotFoundAction.IGNORE)
	public HrCode getType() {
		return this.type;
	}

	public void setType(HrCode type) {
		this.type = type;
	}

	@Transient
	public String getHouseName() {
		if (houseId != null)
			return houseId.getName();
		return houseName;
	}

	public void setHouseName(String houseName) {
		this.houseName = houseName;
	}

	@Transient
	public String getTypeName() {
		if (type != null)
			return type.getCodeDesc();
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	@Transient
	public String getTypeId() {
		if (type != null)
			return type.getCodeId();
		return typeId;
	}

	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}

	@Transient
	public String getImagePath() {
		if (this.image != null && !"".equals(this.image))
			return Constants.WEBAPP_PATH + this.image;
		else
			return this.image;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	@Transient
	public String getHouseid() {
		if (houseId != null)
			return houseId.getId();
		return houseid;
	}

	public void setHouseid(String houseid) {
		this.houseid = houseid;
	}
	
	@Transient
	public String getCreateName() {
		return createName;
	}

	public void setCreateName(String createName) {
		this.createName = createName;
	}
	
	@Transient
	public String getPublisherName() {
		return publisherName;
	}

	public void setPublisherName(String publisherName) {
		this.publisherName = publisherName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "hrNewsInfo")
	public List<NewsHouse> getNewsHouses() {
		return newsHouses;
	}

	public void setNewsHouses(List<NewsHouse> newsHouses) {
		this.newsHouses = newsHouses;
	}
	
}